//
//  HEActiveCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/11/25.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEActiveCell.h"
#import "HEActiveModel.h"

@interface HEActiveCell ()

@property (nonatomic, strong) UILabel *titleLb;
@property (nonatomic, strong) UILabel *startTimeLb;

@property (nonatomic, strong) UILabel *activeNameLb;
@property (nonatomic, strong) UILabel *acTimeLb;
@property (nonatomic, strong) UILabel *acContentLb;
@property (nonatomic, strong) UILabel *acAddressLb;
@property (nonatomic, strong) UILabel *acOrgLb;
@property (nonatomic, strong) UILabel *acTypeLb;

@end

@implementation HEActiveCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = CLightGrayColor;

        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    UIView *warp = [UIView new];
    warp.backgroundColor = KWhiteColor;
    [self.contentView addSubview:warp];
 
    warp.layer.shadowColor = [UIColor colorWithRed:13/255.0 green:98/255.0 blue:218/255.0 alpha:0.08].CGColor;
    warp.layer.shadowOffset = CGSizeMake(0,5);
    warp.layer.shadowOpacity = 1;
    warp.layer.shadowRadius = 6;
    warp.layer.cornerRadius = 10;
 
    [warp mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(0);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(self.contentView).mas_offset(-15);
        make.bottom.equalTo(self.contentView).mas_offset(-15);
    }];
    
    
    // head
    UIView *blueLine = [UIView new];
    blueLine.backgroundColor = CNavBgColor;
    [warp addSubview:blueLine];
    
    _titleLb = [UILabel new];
    _titleLb.text = @"活动";
    _titleLb.font = DYBlodFont(18);
    [warp addSubview:_titleLb];
    
    
    _startTimeLb = [UILabel new];
    _startTimeLb.text = @"2018-20-10";
    _startTimeLb.font = DYFont(16);
    _startTimeLb.textColor = CNavDargGrayColor;
    _startTimeLb.textAlignment = NSTextAlignmentRight;
    [warp addSubview:_startTimeLb];
    
    UIView *headBottomLine = [UIView new];
    headBottomLine.backgroundColor = CSplitLineColor;
    [warp addSubview: headBottomLine];
    
    [blueLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_titleLb);
        make.left.equalTo(warp).offset(10);
        make.width.offset(3);
        make.height.offset(20);
    }];
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(warp).offset(15);
        make.left.equalTo(blueLine.mas_right).offset(10);
        make.right.equalTo(_startTimeLb.mas_left).offset(-10);
    }];
    
    [_startTimeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_titleLb);
        make.right.equalTo(warp).offset(-15);
    }];
    
    [headBottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLb.mas_bottom).offset(15);
        make.left.equalTo(warp).offset(10);
        make.right.equalTo(warp).offset(-10);
        make.height.offset(1);
    }];

    
    // middle
    _activeNameLb = [UILabel new];
    _activeNameLb.text = @"活动报名成功";
    _activeNameLb.font = DYBlodFont(16);
    [warp addSubview: _activeNameLb];
  
    UILabel *timeTitlLb = [UILabel new];
    timeTitlLb.text = @"活动时间：";
    timeTitlLb.font = DYBlodFont(16);
    [warp addSubview: timeTitlLb];
    
    UILabel *cntTitlLb = [UILabel new];
    cntTitlLb.text = @"活动内容：";
    cntTitlLb.font = DYBlodFont(16);
    [warp addSubview: cntTitlLb];
    
    UILabel *addressTitlLb = [UILabel new];
    addressTitlLb.text = @"活动地点：";
    addressTitlLb.font = DYBlodFont(16);
    [warp addSubview: addressTitlLb];
    
    UILabel *orgTitlLb = [UILabel new];
    orgTitlLb.text = @"主办单位：";
    orgTitlLb.font = DYBlodFont(16);
    [warp addSubview: orgTitlLb];
    
    UILabel *typeTitlLb = [UILabel new];
    typeTitlLb.text = @"参与方式：";
    typeTitlLb.font = DYBlodFont(16);
    [warp addSubview: typeTitlLb];
    
    
    [_activeNameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headBottomLine.mas_bottom).offset(15);
        make.left.equalTo(warp).offset(10);
        make.right.equalTo(warp).offset(-10);
    }];
     
    _acTimeLb = [UILabel new];
    _acTimeLb.text = @"-";
    _acTimeLb.font = DYFont(16);
    _acTimeLb.textColor = CNavDargGrayColor;
    _acTimeLb.numberOfLines = 0;
    [warp addSubview: _acTimeLb];
    
    _acContentLb = [UILabel new];
    _acContentLb.text = @"-";
    _acContentLb.font = DYFont(16);
    _acContentLb.textColor = CNavDargGrayColor;
    _acContentLb.numberOfLines = 0;
    [warp addSubview: _acContentLb];
    
    _acAddressLb = [UILabel new];
    _acAddressLb.text = @"-";
    _acAddressLb.font = DYFont(16);
    _acAddressLb.textColor = CNavDargGrayColor;
    _acAddressLb.numberOfLines = 0;
    [warp addSubview: _acAddressLb];
    
    _acOrgLb = [UILabel new];
    _acOrgLb.text = @"-";
    _acOrgLb.font = DYFont(16);
    _acOrgLb.textColor = CNavDargGrayColor;
    _acOrgLb.numberOfLines = 0;
    [warp addSubview: _acOrgLb];
    
    _acTypeLb = [UILabel new];
    _acTypeLb.text = @"-";
    _acTypeLb.font = DYFont(16);
    _acTypeLb.textColor = CNavDargGrayColor;
    _acTypeLb.numberOfLines = 0;
    [warp addSubview: _acTypeLb];
    
    
    // title -
    [timeTitlLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_activeNameLb.mas_bottom).offset(10);
        make.left.equalTo(_activeNameLb.mas_left);
    }];
    [timeTitlLb setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];

    [cntTitlLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_acTimeLb.mas_bottom).offset(10);
        make.left.equalTo(_activeNameLb.mas_left);
    }];
    
    [cntTitlLb setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];

    [addressTitlLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_acContentLb.mas_bottom).offset(10);
        make.left.equalTo(_activeNameLb.mas_left);
    }];
    [addressTitlLb setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    
    [orgTitlLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_acAddressLb.mas_bottom).offset(10);
        make.left.equalTo(_activeNameLb.mas_left);
    }];
    [orgTitlLb setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];

    
    [typeTitlLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_acOrgLb.mas_bottom).offset(10);
        make.left.equalTo(_activeNameLb.mas_left);
    }];
    [typeTitlLb setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];

     
    // cnt --
    [_acTimeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_activeNameLb.mas_bottom).offset(10);
        make.left.equalTo(timeTitlLb.mas_right);
        make.right.equalTo(warp).offset(-10);
    }];
    
    [_acContentLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_acTimeLb.mas_bottom).offset(10);
        make.left.equalTo(cntTitlLb.mas_right);
        make.right.equalTo(warp).offset(-10);
    }];
    
    [_acAddressLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_acContentLb.mas_bottom).offset(10);
        make.left.equalTo(addressTitlLb.mas_right);
        make.right.equalTo(warp).offset(-10);
    }];
    
    [_acOrgLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_acAddressLb.mas_bottom).offset(10);
        make.left.equalTo(orgTitlLb.mas_right);
        make.right.equalTo(warp).offset(-10);
    }];
    
    [_acTypeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_acOrgLb.mas_bottom).offset(10);
        make.left.equalTo(typeTitlLb.mas_right);
        make.right.equalTo(warp).offset(-10);
    }];
    
    //  footer
    UIView *footerTopLine = [UIView new];
    footerTopLine.backgroundColor = CSplitLineColor;
    [warp addSubview: footerTopLine];
    [footerTopLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_acTypeLb.mas_bottom).offset(15);
        make.left.equalTo(warp).offset(10);
        make.right.equalTo(warp).offset(-10);
        make.height.offset(1);
    }];
    
    UILabel *checkLb = [UILabel new];
    checkLb.text = @"立即查看";
    checkLb.font = DYFont(16);
    [warp addSubview: checkLb];
    
    [checkLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(footerTopLine.mas_bottom).offset(15);
        make.left.equalTo(warp).offset(10);
        make.bottom.equalTo(warp.mas_bottom).offset(-15);
    }];
    
    UIImageView *_arrowView = [UIImageView new];
    _arrowView.contentMode = UIViewContentModeScaleAspectFill;
    _arrowView.image = IMAGE_NAMED(@"go_gray");
    [warp addSubview:_arrowView];
    
    [_arrowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(checkLb);
        make.right.equalTo(warp).mas_offset(-15);
        make.width.mas_offset(8);
        make.height.mas_offset(12);
    }];
}

- (void)refreshContent:(GDFiterCellModel *)fiterModel formModel:(GDFormModel *)formModel indexPath:(NSIndexPath *)indexPath {
    
}

- (void)configCellWithModel:(HEActiveModel *)model {
    _activeNameLb.text = model.active_name;
    _acTimeLb.text = model.KStartDate;
    _acContentLb.text = model.brief;
    _acAddressLb.text = model.active_addr;
    _acOrgLb.text = model.active_org;
    _acTypeLb.text = model.active_secret;
    
    _startTimeLb.text = [NSDate chatingTime: model.create_date];
    
    [self showbadge: model.showRead];
}

- (void)showbadge:(BOOL)show {
  
    if (show) {
        [_startTimeLb pp_showBadge];
        _startTimeLb.badgeView.font = DYBlodFont(14);
        [_startTimeLb pp_addDotWithColor: CPriceColor];
        [_startTimeLb pp_setBadgeHeight: 12];
        [_startTimeLb pp_moveBadgeWithX: 5 Y: 0];
    }else {
        [_startTimeLb pp_hiddenBadge];
    }
}

@end
